package com.tskj.leonsu.service;

import com.alibaba.fastjson.JSONArray;
import com.tskj.leonsu.dao.StudyRoomDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudyRoomService {

    @Autowired
    private StudyRoomDAO studyRoomDAO;

    public JSONArray getUnFinishedOrder(String adUserName) {
        return studyRoomDAO.getUnFinishedOrder(adUserName);
    }

    public JSONArray getFinishedOrder(String adUserName) {
        return studyRoomDAO.getFinishedOrder(adUserName);
    }

    public JSONArray getAllOrder(String adUserName) {
        return studyRoomDAO.getAllOrder(adUserName);
    }

    public void confirmOrder(String adUserName, String id) throws Exception {
        if (studyRoomDAO.getCanConfirm(id)) {
            studyRoomDAO.confirmOrder(adUserName, id);
        } else {
            throw new Exception("订单确认失败，未到允许订单确认时间");
        }
    }

    public void cancelOrder(String adUserName, String id) throws Exception {
        if (studyRoomDAO.getCanCancel(id)) {
            studyRoomDAO.cancelOrder(adUserName, id);
        } else {
            throw new Exception("订单取消失败，超过订单取消时间");
        }
    }
}
